package com.wenju.inappupdatemodule.utils;

import android.content.Context;
import com.wenju.inappupdatemodule.R;

public class UpdateHelper {
    private static UpdateHelper instance;
    //自定义资源
    private static int mBuliderSmallIcon;
    private static String mNoUpdateDialogTitle;
    private static String mNoUpdateDialogContext;
    private static String mNoUpdateDialogConfirm;
    private static String mNewUpdateTitle;
    private static String mNewUpdatePositiveButton;
    private static String mNewUpdateNegativeButton;
    private static String mDwonProgressDialogTitle;
    private static String mDownProgressDialogNegativeButton;
    private static String mDownProgressDialogPositiveButton;
    private static String mContinuouslyOpenServicePrompts;
    private static String mDownFail;
    private static String mDownSuccess;
    private static String mDownSuccessToast;
    private static String mDownStop;
    private static String mNotificationName;
    private static String mBuilderTicker;
    private static String mBuilderContext;
    private static String mNotificationId;
    private static String mNotificationChannelId;


    //上下文
    private static Context mContext;
    //是否显示下载进度
    private boolean showProgressDialog;
    //下载是否取消
    private boolean downloadCancle = false;
    //下载类型，默认自动安装
    private DownType downType = DownType.down_auto_Install;
    //下载更新类型
    public enum DownType {
        down_auto_Install,
        down_click_Install
    }

    public static UpdateHelper getInstance() {
        if (instance == null) {
            throw new RuntimeException("未进行初始化!");
        } else {
            mBuliderSmallIcon = R.mipmap.ic_launcher;
            mNoUpdateDialogTitle = mContext.getString(R.string.no_update_dialog_title);
            mNoUpdateDialogContext = mContext.getString(R.string.no_update_dialog_context);
            mNoUpdateDialogConfirm = mContext.getString(R.string.no_update_dialog_confirm);
            mNewUpdateTitle = mContext.getString(R.string.new_update_title);
            mNewUpdatePositiveButton = mContext.getString(R.string.new_update_positive_button);
            mNewUpdateNegativeButton = mContext.getString(R.string.new_update_negative_button);
            mDwonProgressDialogTitle = mContext.getString(R.string.dwon_progress_dialog_title);
            mDownProgressDialogNegativeButton = mContext.getString(R.string.down_progress_dialog_negative_button);
            mDownProgressDialogPositiveButton = mContext.getString(R.string.down_progress_dialog_positive_button);
            mContinuouslyOpenServicePrompts = mContext.getString(R.string.continuously_open_service_prompts);
            mDownFail = mContext.getString(R.string.down_fail);
            mDownSuccess = mContext.getString(R.string.down_success);
            mDownSuccessToast = mContext.getString(R.string.down_success_toast);
            mDownStop = mContext.getString(R.string.down_stop);
            mNotificationName = mContext.getString(R.string.notification_name);
            mBuilderTicker = mContext.getString(R.string.builder_ticker);
            mBuilderContext = mContext.getString(R.string.builder_context);
            mNotificationId = mContext.getString(R.string.notification_id);
            mNotificationChannelId = mContext.getString(R.string.notification_channel_id);
            return instance;
        }
    }


    public static void init(Context appContext) {
        instance = new UpdateHelper(appContext);
    }

    private UpdateHelper(Context context) {
        this.mContext = context;

    }

    public UpdateHelper setDownType(DownType downType) {
        this.downType = downType;
        return this;
    }

    public UpdateHelper showProgressDialog(boolean showProgressDialog) {
        this.showProgressDialog = showProgressDialog;
        return this;
    }

    public DownType getDownType() {
        return downType;
    }

    public boolean isShowProgressDialog() {
        return showProgressDialog;
    }

    public boolean isDownloadCancle() {
        return downloadCancle;
    }

    public void setDownloadCancle(boolean downloadCancle) {
        this.downloadCancle = downloadCancle;
    }


    public static void setInstance(UpdateHelper instance) {
        UpdateHelper.instance = instance;
    }

    public static int getmBuliderSmallIcon() {
        return mBuliderSmallIcon;
    }

    public UpdateHelper setmBuliderSmallIcon(int mBuliderSmallIcon) {
        UpdateHelper.mBuliderSmallIcon = mBuliderSmallIcon;
        return this;
    }

    public String getmNoUpdateDialogTitle() {
        return mNoUpdateDialogTitle;
    }

    public UpdateHelper setmNoUpdateDialogTitle(String mNoUpdateDialogTitle) {
        this.mNoUpdateDialogTitle = mNoUpdateDialogTitle;
        return this;
    }

    public String getmNoUpdateDialogContext() {
        return mNoUpdateDialogContext;
    }

    public UpdateHelper setmNoUpdateDialogContext(String mNoUpdateDialogContext) {
        this.mNoUpdateDialogContext = mNoUpdateDialogContext;
        return this;
    }

    public String getmNoUpdateDialogConfirm() {
        return mNoUpdateDialogConfirm;
    }

    public UpdateHelper setmNoUpdateDialogConfirm(String mNoUpdateDialogConfirm) {
        this.mNoUpdateDialogConfirm = mNoUpdateDialogConfirm;
        return this;
    }

    public String getmNewUpdateTitle() {
        return mNewUpdateTitle;
    }

    public UpdateHelper setmNewUpdateTitle(String mNewUpdateTitle) {
        this.mNewUpdateTitle = mNewUpdateTitle;
        return this;
    }

    public String getmNewUpdatePositiveButton() {
        return mNewUpdatePositiveButton;
    }

    public UpdateHelper setmNewUpdatePositiveButton(String mNewUpdatePositiveButton) {
        this.mNewUpdatePositiveButton = mNewUpdatePositiveButton;
        return this;
    }

    public String getmNewUpdateNegativeButton() {
        return mNewUpdateNegativeButton;
    }

    public UpdateHelper setmNewUpdateNegativeButton(String mNewUpdateNegativeButton) {
        this.mNewUpdateNegativeButton = mNewUpdateNegativeButton;
        return this;
    }

    public String getmDwonProgressDialogTitle() {
        return mDwonProgressDialogTitle;
    }

    public UpdateHelper setmDwonProgressDialogTitle(String mDwonProgressDialogTitle) {
        this.mDwonProgressDialogTitle = mDwonProgressDialogTitle;
        return this;
    }

    public String getmDownProgressDialogNegativeButton() {
        return mDownProgressDialogNegativeButton;
    }

    public UpdateHelper setmDownProgressDialogNegativeButton(String mDownProgressDialogNegativeButton) {
        this.mDownProgressDialogNegativeButton = mDownProgressDialogNegativeButton;
        return this;
    }

    public String getmDownProgressDialogPositiveButton() {
        return mDownProgressDialogPositiveButton;
    }

    public UpdateHelper setmDownProgressDialogPositiveButton(String mDownProgressDialogPositiveButton) {
        this.mDownProgressDialogPositiveButton = mDownProgressDialogPositiveButton;
        return this;
    }

    public String getmContinuouslyOpenServicePrompts() {
        return mContinuouslyOpenServicePrompts;
    }

    public UpdateHelper setmContinuouslyOpenServicePrompts(String mContinuouslyOpenServicePrompts) {
        this.mContinuouslyOpenServicePrompts = mContinuouslyOpenServicePrompts;
        return this;
    }

    public String getmDownFail() {
        return mDownFail;
    }

    public UpdateHelper setmDownFail(String mDownFail) {
        this.mDownFail = mDownFail;
        return this;
    }

    public String getmDownSuccess() {
        return mDownSuccess;
    }

    public UpdateHelper setmDownSuccess(String mDownSuccess) {
        this.mDownSuccess = mDownSuccess;
        return this;
    }

    public String getmDownSuccessToast() {
        return mDownSuccessToast;
    }

    public UpdateHelper setmDownSuccessToast(String mDownSuccessToast) {
        this.mDownSuccessToast = mDownSuccessToast;
        return this;
    }

    public String getmDownStop() {
        return mDownStop;
    }

    public UpdateHelper setmDownStop(String mDownStop) {
        this.mDownStop = mDownStop;
        return this;
    }

    public String getmNotificationName() {
        return mNotificationName;
    }

    public UpdateHelper setmNotificationName(String mNotificationName) {
        this.mNotificationName = mNotificationName;
        return this;
    }

    public String getmBuilderTicker() {
        return mBuilderTicker;
    }

    public UpdateHelper setmBuilderTicker(String mBuilderTicker) {
        this.mBuilderTicker = mBuilderTicker;
        return this;
    }

    public String getmBuilderContext() {
        return mBuilderContext;
    }

    public UpdateHelper setmBuilderContext(String mBuilderContext) {
        this.mBuilderContext = mBuilderContext;
        return this;
    }

    public String getmNotificationId() {
        return mNotificationId;
    }

    public UpdateHelper setmNotificationId(String mNotificationId) {
        this.mNotificationId = mNotificationId;
        return this;
    }

    public String getmNotificationChannelId() {
        return mNotificationChannelId;
    }

    public UpdateHelper setmNotificationChannelId(String mNotificationChannelId) {
        this.mNotificationChannelId = mNotificationChannelId;
        return this;
    }

}
